﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;

namespace YJKView
{
	public class ViewJumpControler
	{
		public static void Sort(List<ViewPlan> viewPlanList, bool isAscending)
		{
			bool flag = false;
			int num = 1;
			while (num < viewPlanList.Count && !flag)
			{
				flag = true;
				for (int i = 0; i < viewPlanList.Count - num; i++)
				{
					try
					{
						if (isAscending)
						{
							if (ViewJumpControler.GreaterThan(viewPlanList[i].GenLevel.Elevation, viewPlanList[i + 1].GenLevel.Elevation))
							{
								flag = false;
								ViewPlan value = viewPlanList[i];
								viewPlanList[i] = viewPlanList[i + 1];
								viewPlanList[i + 1] = value;
							}
						}
						else if (ViewJumpControler.LessThan(viewPlanList[i].GenLevel.Elevation, viewPlanList[i + 1].GenLevel.Elevation))
						{
							flag = false;
							ViewPlan value = viewPlanList[i];
							viewPlanList[i] = viewPlanList[i + 1];
							viewPlanList[i + 1] = value;
						}
					}
					catch
					{
					}
				}
				num++;
			}
		}

		public static bool LessThan(double val1, double val2)
		{
			return val1 - val2 < -1E-09;
		}

		public static bool GreaterThan(double val1, double val2)
		{
			return val1 - val2 > 1E-09;
		}

		public static bool IsEqual(double val1, double val2)
		{
			return !ViewJumpControler.LessThan(val1, val2) && !ViewJumpControler.LessThan(val2, val1);
		}

		public static bool Lessthan_Or_Equal(double val1, double val2)
		{
			return !ViewJumpControler.GreaterThan(val1, val2);
		}

		public static bool Greaterthan_Or_Equal(double val1, double val2)
		{
			return !ViewJumpControler.LessThan(val1, val2);
		}

		private const double _epsDouble = 1E-09;
	}
}
